# !/usr/bin/env python
# -*- coding:utf-8 -*-


from PyQt6.QtCore import pyqtSignal, QTimer
from PyQt6.QtWidgets import QDialog
from page.tishi import Ui_Tishi


# ==============================================================================
# page 6.提示框
# ==============================================================================


class Tishi(QDialog, Ui_Tishi):
    """提示信息页面"""
    confirmed_signal = pyqtSignal()

    def __init__(self):
        super().__init__()
        self.timer = None
        self.setupUi(self)
        self.is_message_box_open = False  # 标志变量，跟踪提示框的状态
        self.label.setWordWrap(True)  # 提示文本，自动换行
        self.qr = 0  # 确认按钮，标识

    def xinxi(self, vale, q=False):
        """输入提示信息，5秒自动关闭"""
        self.pushButton.setVisible(q)  # 隐藏（取消显示）确认按钮
        self.qr = 0

        self.timer = QTimer()
        self.label.setText(vale)  # 弹窗提示信息
        if self.is_message_box_open:
            self.close()  # 关闭旧的提示框
            self.timer.stop()  # 停止旧的计时器

        self.pushButton.setEnabled(True)  # 按钮恢复
        self.is_message_box_open = True
        self.timer.setSingleShot(True)  # 单次触发模式
        self.timer.timeout.connect(self.close)
        self.timer.start(6000)  # 5000毫秒等于5秒
        self.open()
        self.exec()  # 置顶，其它窗口不能操作

    def queren(self):
        """确认按钮"""
        self.close()  # 弹窗确认按钮
        self.qr = 1
